package simulation;

/**
 * @author cwhalen
 * 
 */
public class Sun
{
	private double lattitude;
	private double longitude;


	/**
	 * @return
	 */
	public double getLattitude()
	{
		return lattitude;
	}


	/**
	 * @return
	 */
	public double getLongitude()
	{
		return longitude;
	}


	/**
	 * @param longitude
	 */
	public void setLongitude(double longitude)
	{
		this.longitude = longitude;
	}


	/**
	 * @param degree
	 */
	public void moveSun(double degree)
	{
		double tempLon = this.longitude + degree;

		if (tempLon > 180)
		{
			setLongitude(-180 + (tempLon % 180));
		} else
		{
			setLongitude(tempLon);
		}
	}


	/**
	 * @param lattitude
	 * @param longitude
	 */
	public Sun(double lattitude, double longitude)
	{
		this.lattitude = lattitude;
		this.longitude = longitude;
	}


	/**
	 * @param tL
	 * @param bL
	 * @param lL
	 * @param rL
	 * @return
	 */
	public float cRadiationFactor(float tL, float bL, float lL, float rL)
	{
		// Average the lattitudes and longitudes to get a middle reading to
		// compute for
		float aveLat = (tL + bL) / 2;
		float aveLon = (lL + rL) / 2;

		// Lattitude radiation will not change since the sun does not move up
		// and down in lattitude
		double latRadiation = Math.cos(Math.toRadians(aveLat));

		// Longitude radiation changes based on the lonitude movement of the sun
		double lonRadiation = Math.cos(Math.toRadians(aveLon - this.longitude));

		// FIXME : Need to propperly account for cooling. If the sun is not
		// shining on a Node then the sun's temperature is 0
		if (lonRadiation < 0)
		{
			return (float)((-1 * (latRadiation +(-1*lonRadiation))) / 2);
		} else
		{
			// The total heat radiation will be the average of the lattitude and
			// longitude radiation
			return (float)((latRadiation + lonRadiation) / 2);
		}
	}

}
